package com.itzb.asone.system.service.impl;


import java.util.List;

import com.itzb.asone.mybatis.Criteria;
import com.itzb.asone.system.model.SysGroup;
import com.itzb.asone.system.model.SysGroupUser;
import com.itzb.asone.system.repository.ISysGroupRepository;
import com.itzb.asone.system.repository.ISysGroupUserRepository;
import com.itzb.asone.system.service.IMessageService;
import com.itzb.asone.system.service.ISysGroupService;

public class SysGroupServiceImpl implements ISysGroupService{
	
	private ISysGroupRepository sysGroupRepository;
	private ISysGroupUserRepository sysGroupUserRepository;
	private IMessageService messageService;

	public List<SysGroup> queryPage(Criteria<SysGroup> param){
		return sysGroupRepository.queryPage(param);
	}

	public Integer queryPageCount(Criteria<SysGroup> param){
		return sysGroupRepository.queryPageCount(param);
	}

	public SysGroup getGroupByUserId(String userId){
		SysGroup sysGroup = new SysGroup();
		Criteria<SysGroupUser> param = new Criteria<SysGroupUser>();
		param.addParam("userId", userId);
		List<SysGroupUser> sysGroupUserList = sysGroupUserRepository.queryPage(param);
		if(sysGroupUserList != null && sysGroupUserList.size() > 0){
			SysGroupUser sysGroupUser = sysGroupUserList.get(0);
			sysGroup = sysGroupRepository.queryEntityById(sysGroupUser.getGroupId());
		}
		
		return sysGroup;
	}
	
	public SysGroup queryEntityById(String id){
		return sysGroupRepository.queryEntityById(id);
	}

	public Integer insert(SysGroup record){
		return sysGroupRepository.insert(record);
	}

	public Integer updateByCriteria(Criteria<SysGroup> param){
		return sysGroupRepository.updateByCriteria(param);
	}

	public Integer deleteById(String id){
		return sysGroupRepository.deleteById(id);
	}

	public Integer deleteByCriteria(Criteria<SysGroup> param){
		return sysGroupRepository.deleteByCriteria(param);
	}

	public ISysGroupRepository getSysGroupRepository() {
		return sysGroupRepository;
	}

	public void setSysGroupRepository(ISysGroupRepository sysGroupRepository) {
		this.sysGroupRepository = sysGroupRepository;
	}

	public IMessageService getMessageService() {
		return messageService;
	}

	public void setMessageService(IMessageService messageService) {
		this.messageService = messageService;
	}

	public ISysGroupUserRepository getSysGroupUserRepository() {
		return sysGroupUserRepository;
	}

	public void setSysGroupUserRepository(
			ISysGroupUserRepository sysGroupUserRepository) {
		this.sysGroupUserRepository = sysGroupUserRepository;
	}

}
